home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / mg / rexx / slashquote < prev    next >
Text File  |  1995-03-09  |  888b  |  35 lines

  1. /*
  2.  * slashquote - Take the first char of the second arg (it should be a single
  3.  * char anyway, but we be paranoid), and put's that character in front of
  4.  * any double-quotes or occurenses of that charater in the string that is
  5.  * the first arg, and returns the result with double quotes around it.
  6.  *
  7.  * Usefull in mg for quoting things to be inserted when called as:
  8.  *
  9.  *    slashquote(string_to_insert, '\')
  10.  *
  11.  * and for things to issue to a shell if called as:
  12.  *
  13.  *    slashquote(command_argument_to_fix, '*')
  14.  *
  15.  * There are probably other uses for the silly thing.
  16.  *
  17.  */
  18.  
  19. parse arg in, char
  20.  
  21. char = left(char, 1)
  22. i = index(in, char)
  23. do while i > 0
  24.     in = substr(in, 1, i - 1) || char || char || substr(in, i + 1)
  25.     i = index(in, char, i + 2)
  26.     end
  27.  
  28. i = index(in, '"')
  29. do while i > 0
  30.     in = substr(in, 1, i - 1) || char'"'substr(in, i + 1)
  31.     i = index(in, '"', i + 2)
  32.     end
  33.  
  34. return '"'in'"'
  35.